package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/admin/order")
@RestController("adminOrderController")
@Slf4j
@Api(tags = "订单管理相关接口")
public class OrderController {
    @Autowired
    private OrderService orderService;


    /*订单搜索*/
    @GetMapping("/conditionSearch")
    @ApiOperation(value = "订单搜索", httpMethod = "GET")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("订单搜索,{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /*各个订单状态查询*/
    @GetMapping("/statistics")
    @ApiOperation(value = "各个订单状态查询", httpMethod = "GET")
    public Result<OrderStatisticsVO> statistics() {
        log.info("各个订单状态查询,{}");
        OrderStatisticsVO orderStatisticsVO = orderService.getBystatus();
        return Result.success(orderStatisticsVO);
    }

    /*根据id查询订单详情*/
    @GetMapping("/details/{id}")
    @ApiOperation(value = "根据id查询订单详情", httpMethod = "GET")
    public Result<OrderVO> details(@PathVariable Long id) {
        log.info("根据id查询订单详情,{}", id);
        OrderVO orderVO = orderService.getOrderDetailById(id);
        return Result.success(orderVO);
    }

    /*接单*/
    @PutMapping("/confirm")
    @ApiOperation(value = "接单", httpMethod = "PUT")
    public Result confirm(@RequestBody OrderVO orderVO) {
        log.info("接单,{}", orderVO);
        orderService.confirm(orderVO);
        return Result.success();
    }


    /*拒绝订单*/
    @PutMapping("/rejection")
    @ApiOperation(value = "拒绝订单", httpMethod = "PUT")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("拒绝订单,{}", ordersRejectionDTO);
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /*取消订单*/
    @PutMapping("/cancel")
    @ApiOperation(value = "取消订单", httpMethod = "PUT")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("取消订单,{}", ordersCancelDTO);
        orderService.cancelAdminOrder(ordersCancelDTO);
        return Result.success();
    }

    /*派送订单*/
    @PutMapping("/delivery/{id}")
    @ApiOperation(value = "派送订单", httpMethod = "PUT")
    public Result delivery(@PathVariable Long id) {
        log.info("派送订单,{}", id);
        orderService.delivery(id);
        return Result.success();
    }

    //完成订单
    @PutMapping("/complete/{id}")
    @ApiOperation(value = "完成订单", httpMethod = "PUT")
    public Result complete(@PathVariable Long id) {
        log.info("完成订单,{}", id);
        orderService.complete(id);
        return Result.success();
    }
}
